package com.polaris.live.widget

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import android.widget.RelativeLayout
import androidx.annotation.DrawableRes
import com.polaris.live.common.constant.PagConst.USER_STATUS_PAG
import com.polaris.live.databinding.WidgetUserStatusBinding

/**
 * 用户状态控件
 *
 * @author Created by 长空 on 2023/12/24 16:32
 * @since 1.0.0
 */
class UserStatusView(context: Context, attributeSet: AttributeSet) :
    RelativeLayout(context, attributeSet) {

    private val mBinding = WidgetUserStatusBinding.inflate(LayoutInflater.from(context), this)

    /**
     * 设置语言
     */
    fun setImageResource(@DrawableRes resId: Int?) {
        if (resId != null) {
            mBinding.ivState.setImageResource(resId)
            mBinding.pagState.visibility = View.GONE
            mBinding.ivState.visibility = View.VISIBLE
        } else {
            mBinding.pagState.visibility = View.VISIBLE
            mBinding.ivState.visibility = View.GONE
            mBinding.pagState.apply {
                path = USER_STATUS_PAG
                setRepeatCount(-1)
                play()
            }
        }
    }
}